home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
C
/
Applications
/
Fixation 1.3
/
util.c
< prev
next >
Wrap
Text File
|
1996-02-02
|
3KB
|
118 lines
// util.c
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include "mytypes.h"
#include "main.h"
#include "window.h"
#include "ResRefs.h"
#include "util.h"
#include "error.h"
#include "preffile.h"
#include "incoming.h"
#include "globals.h"
uchar gScratch[kGScratchSize];
char *buffer;
// pop up a simple alert with given string as the text, one okay button
void stdmessage(Str255 s)
{
ParamText(s, "\p", "\p", "\p");
(void) Alert(rmessagealrt, nil);
}
void tprintf( char * format, ... )
{
va_list params;
short len;
static Boolean lastPrompt = false;
va_start(params,format);
len = vsprintf( buffer, format, params );
verify(len <= kGScratchSize);
if (gPrefs.smartText) {
// you may wish to close your eyes
// the ugliness of the following code may shock you
Boolean same = !strcmp(buffer, gPrompt);
short length = strlen(gPrompt);
gPrompt[length] = '\r'; gPrompt[length+1] = 0;
same |= !strcmp(buffer, gPrompt);
gPrompt[length] = 0;
if (buffer[0] == '\r')
same |= !strcmp(&buffer[1], gPrompt);
if (same) {
if (lastPrompt) {
va_end(params);
return; // we don't need to hear this again, really
}
lastPrompt = true;
}
else if (len > 1 || buffer[0] != '\r')
lastPrompt = false;
if (len == 1 && buffer[0] == '\r' && lastPrompt) {
// this is all getting a little dodgy . . .
va_end(params);
return; // we don't need to hear this again, really
}
}
// if ((**myText).selStart < (**myText).teLength)
// TESetSelect(32767, 32767, myText);
short leng = (**myText).teLength;
short oldstart = (**myText).selStart, oldend = (**myText).selEnd;
(**myText).selStart = leng; (**myText).selEnd = leng;
TEInsert(buffer, len, myText);
(**myText).selStart = oldstart; (**myText).selEnd = oldend;
leng = (**myText).teLength;
// check if we need to clear some space
if (leng > 25000) {
// delete 5K
short cuts = 5000;
// TESetSelect(0, cuts, myText);
(**myText).selStart = 0; (**myText).selEnd = cuts;
TEDelete(myText);
// TESetSelect(32767, 32767, myText);
oldstart -= cuts; oldend -= cuts;
if (oldstart < 0)
oldstart = 0;
if (oldend < 0)
oldend = 0;
(**myText).selStart = oldstart; (**myText).selEnd = oldend;
// maybe this will stop anal leakage
// I mean color leakage, whoops
TEStyleHandle tsh = GetStylHandle(myText);
(**(**(**tsh).nullStyle).nullScrap).scrpStyleTab[0].scrpFace = 0;
(**(**(**tsh).nullStyle).nullScrap).scrpStyleTab[0].scrpColor.red = 0;
(**(**(**tsh).nullStyle).nullScrap).scrpStyleTab[0].scrpColor.green = 0;
(**(**(**tsh).nullStyle).nullScrap).scrpStyleTab[0].scrpColor.blue = 0;
}
if (!gInTheThick || gPrefs.slowText)
CalcVBar();
va_end(params);
}
void
PrintAddress(unsigned long addr)
{
tprintf("%d.%d.%d.%d", (short) (addr >> 24), (short) ((addr<<8) >> 24),
(short) ((addr<<16)>>24), (short) ((addr<<24) >> 24));
}
void
MyInitUtil(void)
{
buffer = (char *) NewPtr(kGScratchSize);
}